package com.lwl.office.dcconverter.element;

import com.lwl.office.dcconverter.style.AbsDCStyle;
import com.lwl.office.dcconverter.style.DCRunStyle;
import com.lwl.office.webeditor.ParserContext;
import lombok.Data;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;

@Data
public class DCRun extends AbsDCElement{
    private String text;
    private DCPic picData;

    @Override
    public String toHtml() {
        StringBuilder stb = new StringBuilder();
        //文本
        if(text!=null){
            stb.append("<span ");
            if(getStyle()!=null){
                stb.append(getStyle().toHtmlStyle());
            }
            stb.append(">");
            stb.append(text);
            stb.append("</span>");
        }
        //图片
        if(picData!=null){
            stb.append(picData.toHtml());
        }
        return stb.toString();
    }

    @Override
    public void parseWord(ParserContext context) {
        XWPFRun run = context.createRun();
        DCRunStyle style = (DCRunStyle) getStyle();
        if(style != null){
            //设置样式
            style.setWordStyle(run);
        }
        //设置文本
        run.setText(text);
    }
}
